package server;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.util.ArrayList;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ScrollPaneConstants;
import javax.swing.table.AbstractTableModel;

public class PassStatusPanel extends JPanel {
	private static final long serialVersionUID = 1L;

	JTable table;

	public PassStatusPanel() {

		table = new JTable(new TableModel());

		JScrollPane scroll = new JScrollPane(table);
		scroll.setPreferredSize(new Dimension(500, 500));
		scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
		scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

		add(scroll, BorderLayout.CENTER);
	}

	private class TableModel extends AbstractTableModel {
		private static final long serialVersionUID = 1L;

		String[] nameList = { "Username", "Password", "Status", "Time Used" };
		ArrayList<RowData> rowList = new ArrayList<RowData>();

		public TableModel() {
			rowList.add(new RowData("User1", "12345", "In Use", "0:35:58"));
			rowList.add(new RowData("User2", "54321", "In Use", "0:53:21"));
			rowList.add(new RowData("User3", "45321", "Pending Use", "2:10:03"));
		}

		public String getColumnName(int n) {
			return nameList[n];
		}

		public int getColumnCount() {
			return nameList.length;
		}

		public int getRowCount() {
			return rowList.size();
		}

		public Object getValueAt(int row, int col) {
			RowData rowData = rowList.get(row);
			return rowData.get(col);
		}

		private class RowData {

			ArrayList<String> list = new ArrayList<String>();

			public RowData(String password, String username, String status,
					String timeUsed) {
				list.add(password);
				list.add(username);
				list.add(status);
				list.add(timeUsed);
			}

			public String get(int col) {
				return list.get(col);
			}
		}

	}

}
